package com.sangmo.fts.api.basic;

import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.data.filter.PageResult;
import com.sangmo.boot.framework.data.json.ExtViewHelper;
import com.sangmo.boot.framework.data.json.context.ExtViewContext;
import com.sangmo.boot.framework.plugin.dataview.data.DataViewPageSearch;
import com.sangmo.fts.basic.interfaces.BankCreation;
import com.sangmo.fts.basic.interfaces.CompanyCreation;
import com.sangmo.fts.basic.interfaces.NoticeCreation;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.service.CompanyService;
import com.sangmo.fts.teacher.model.Examination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.HashMap;

@Controller
@RequestMapping("/company/v1")
public class CompanyApi {

    @Autowired private CompanyService companyService;

    @PostMapping(value = "/create")
    public @ResponseBody
    ApiResponse<Company> create(@RequestBody @Valid CompanyCreation obj) {
        return ApiResponse.make(companyService.create(obj));
    }

    @PostMapping("/search")
    public @ResponseBody ApiResponse<PageResult<Company>> search(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        ExtViewHelper.setGroup("Company.search", 1);
        return ApiResponse.make(companyService.search(ps));
    }

    @PostMapping("/{id}/remove")
    public @ResponseBody ApiResponse remove(@PathVariable("id") Long id) {
        companyService.deleteById(id);
        return ApiResponse.make();
    }

    @PostMapping(value = "/bank/create")
    public @ResponseBody
    ApiResponse<Company> createBank(@RequestBody @Valid BankCreation obj) {
        return ApiResponse.make(companyService.createBank(obj));
    }

    @PostMapping("/selection")
    public @ResponseBody ApiResponse<PageResult<Company>> selection(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        ExtViewHelper.setGroup("CompanyAnn.assuranceSelection", 1);
        return ApiResponse.make(companyService.search(ps));
    }

}
